<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Models\GoodsClass;
use App\Services\GoodsClassService;
use Illuminate\Http\Request;

class GoodsClassController extends Controller
{
    // 获取商品栏目
    public function get_goods_classes(){
        $data = $this->getService('Tool')->getChildren($this->getService('GoodsClass', true)->orderBy('is_sort', 'asc')->get());

        // 去掉&符号和空格 然后取前四位
        foreach($data as &$v){
            $v['name'] = str_replace(['&',' '],'',$v['name']);
            $v['name'] = mb_substr($v['name'],0,4);
        }
        return $this->success($data);
    }

    // 获取指定栏目同级别栏目
    public function get_goods_class_children( $id){
        $classInfo = $this->getService('GoodsClass',true)->find($id);
        $list = $this->getService('GoodsClass',true)->select('id','name')->where('pid',$classInfo['pid'])->get();
        return $this->success($list);
    }
}
